import { reactive, ref } from 'vue'

export function useForm() {
  const initialValues = {
    code: null as string | null,
    orderNumber: null as string | null,
    shopCode: null as string | null,
    shopName: null as string | null,
    warehouseCode: null as string | null,
    warehouseName: null as string | null,
    paymentAmount: null as number | null,
    expressNumber: null as string | null,
    auditStatus: null as string | null,
    remark: null as string | null,
    saleOrderDetailFormList: [] as any[],
    returnOrderDetailFormList: [] as any[]
  }

  const state = reactive({
    detailFormRef: ref(),
    detailForm: { ...initialValues }
  })

  const meta = {
    model: state.detailForm,
    rules: {
      shopCode: [{ required: true, message: '目标门店不能为空', trigger: 'blur' }]
    }
  }

  const initForm = () => {
    state.detailForm = { ...initialValues }
  }

  const resetForm = () => {
    state.detailForm = { ...initialValues }
  }

  const getFormValues = () => state.detailForm

  const setDetail = (record: any) => {
    state.detailForm = { ...record }
  }

  return {
    meta,
    state,
    setDetail,
    initForm,
    resetForm,
    getFormValues
  }
}
